HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/owlcrm/app/Http/Controllers/CommentController.php
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Comment;
use App\Models\Task;
use Illuminate\Support\Facades\Auth;  

class CommentController extends Controller
{
    public function store(Request $request, $task_id)
    {
        $request->validate([
            'comment' => 'required|string|max:500', // Comment is required and should not exceed 500 characters
        ], [
            'comment.required' => 'This field is required.', // Custom error message
            'comment.max' => 'The comment may not be greater than 500 characters.',
        ]);

        $comment = Comment::create([
            'task_id' => $task_id,
            'user_id' => Auth::id(),  
            'comment' => $request->comment,
        ]);

        return response()->json([
            'success' => true,
            'data' => $comment,
        ]);
    }
    public function show($task_id)
{
    // Fetch the task along with its comments
    $task = Task::with('comments')->findOrFail($task_id);

    return view('tasks.show', compact('task'));
}
}